home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1392 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: What is wrong in this code?
  5. Date: Sat, 13 Jan 96 13:13:18 GMT
  6. Organization: none
  7. Message-ID: <821538798snz@genesis.demon.co.uk>
  8. References: <DL2z7o.2K5@scisun.sci.ccny.cuny.edu> <4d7kvv$j8@ub239.dialup.uwa.edu.au>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <4d7kvv$j8@ub239.dialup.uwa.edu.au>
  15.            prye@cyllene.uwa.edu.au "Peter Rye" writes:
  16.  
  17. >>x = pow(x,x);
  18. > ^-------------------- This line is a problem.
  19. >                       I believe this will give rise to 
  20. >                       "undefined behavior" because you 
  21. >                       are modifying x using a function
  22. >                       which takes x as an argument.
  23.  
  24. No, this is perfectly legal. The relevant par of the standard is in 
  25. section 6.3:
  26.  
  27. "Between the previous and next sequence point an object shall have its
  28.  stored value modified at most once by the evaluation of an expression.
  29.  Furthermore, the prior value shall be accessed only to determine the
  30.  value to be stored"
  31.  
  32. This expression meets the requirement of the 2nd sentence hence is legal.
  33. The fact that a function is involved is not important, except that
  34. a function call defines a sequence point. However that would increase,
  35. not reduce the likelihood of an expression being legal and doesn't affect
  36. an expression which is otherwise shown to be legal.
  37.  
  38. -- 
  39. -----------------------------------------
  40. Lawrence Kirby | fred@genesis.demon.co.uk
  41. Wilts, England | 70734.126@compuserve.com
  42. -----------------------------------------
  43.